package com.ljy.jymail.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/*
* 订单确认页需要用的数据
*
* */

public class OrderConfirmVo {


    List<MemberAddressVo> address;//用户收获地址列表
    List<OrderItemVo> items;//所有选中的购物项
    Integer integration; //优惠劵积分信息
//    BigDecimal total;//订单总额
//    BigDecimal payPrice;//应付总额
    String orderToken;//订单防重令牌

    //发票信息...

    @Getter @Setter
    Map<Long,Boolean> stocks;


    public OrderConfirmVo() {
    }

    public OrderConfirmVo(List<MemberAddressVo> address, List<OrderItemVo> items, Integer integration, String orderToken) {
        this.address = address;
        this.items = items;
        this.integration = integration;
        this.orderToken = orderToken;
    }

    public String getOrderToken() {
        return orderToken;
    }

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }

    @Override
    public String toString() {
        return "OrderConfirmVo{" +
                "address=" + address +
                ", items=" + items +
                ", integration=" + integration +
                ", orderToken='" + orderToken + '\'' +
                '}';
    }

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }

        return sum;
    }



    public BigDecimal getPayPrice() {

        return getTotal();
    }

    public Integer getCount(){
        Integer i = 0;
        if (items!=null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                i += item.getCount();
            }
        }
        return i;
    }


}
